package com.beck.util;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Test {

	public static void main(String[] args) throws Throwable {
		 

		String uuid=UUID.randomUUID().toString();
		String htmlBasePath="D:\\test\\java-pdf-master\\java-pdf-master\\study_simple_demo-master\\src\\main\\resources\\template";//html的根目录
		String tempathBasePath=Test.class.getResource("/").getPath()+"template/";//模板路径
		String pdfBasePath="D:\\test\\java-pdf-master\\java-pdf-master\\study_simple_demo-master\\src\\main\\resources\\template";//生成的pdf目录

		String htmlPath=htmlBasePath+uuid+".html";
		String pdfPath=pdfBasePath+uuid+".pdf";
		

		//生成html
		FreemarkerTemplate tp=new FreemarkerTemplate("UTF-8");
		tp.setTemplateDirectoryPath(tempathBasePath);
		//封装数据 start ，必须是Map
		Map<String, Object> dataMap = new HashMap<String, Object>();
	/*	dataMap.put("outboundTime","2020-01-09");
		dataMap.put("carNo","赣 E27237");
		dataMap.put("warehouseCode", "长沙");
		dataMap.put("deliverCode", "460041100");
		dataMap.put("materialCode", "KA442047900");
		dataMap.put("materialName", "净水机WTE-PT135-2X619F顶(墨石蓝)(GREE)");
		dataMap.put("accidentType","箱损");
		dataMap.put("num","333");
		dataMap.put("amount","123123");*/
		//费用明细
		List<Receipt> receiptList=new ArrayList<Receipt>();//Receipt 必须是public类型的类
		Receipt r1=new Receipt();
		r1.setReceiptType("普通发票");
		r1.setAmount(100);
		
		Receipt r2=new Receipt();
		r2.setReceiptType("普通发票");
		r2.setAmount(100);

		Receipt r3=new Receipt();
		r3.setReceiptType("普通发票");
		r3.setAmount(100);

		Receipt r4=new Receipt();
		r4.setReceiptType("普通发票");
		r4.setAmount(100);

		Receipt r5=new Receipt();
		r5.setReceiptType("普通发票");
		r5.setAmount(100);
		receiptList.add(r1);
		receiptList.add(r2);
		receiptList.add(r3);
		receiptList.add(r4);
		receiptList.add(r5);
		receiptList.forEach(x->{
			x.setAccidentType("箱损");
			x.setWarehouseCode("长沙");
			x.setOutboundDate("2020-08-04");
			x.setCarNo("赣 E27237");
			x.setDeliverCode("460041100");
			x.setMaterialCode("KA442047900");
			x.setMaterialName("KF-35GW/(35359)NhAb-3(含管) 顶(清爽白)");
			x.setNum("33");
		});
		
		dataMap.put("receiptList", receiptList);

		Map<String, Object> dataMap2 = new HashMap<String, Object>();
		//封装数据 end
		//List<File> htmlFiles = new ArrayList<File>();
		List<String> htmlStrs = new ArrayList<String>();
		htmlStrs.add(tp.processToString("expense1.html", dataMap));
		htmlStrs.add(tp.processToString("expense2.html",createDataMap2()));
		//File htmlFile=new File(htmlPath);
		//tp.processToFile("expense1.html", dataMap,htmlFile);
		//htmlFiles.add(htmlFile);
		//File htmlFile1=new File(htmlPath);
		//tp.processToFile("expense1.html", dataMap,htmlFile);
		//htmlFiles.add(htmlFile1);
		System.out.println("生成html完成！");
		//生成pdf
		PDFUtils.htmlFileToPDFFiles(htmlStrs, new File(pdfPath), new File(htmlBasePath));
		System.out.println("生成pdf完成！" + pdfPath);
		

	}


	private static Map<String,Object> createDataMap2(){
		Map<String, Object> dataMap2 = new HashMap<String, Object>();
		List<Receipt> list = new ArrayList<>();
		for (int i = 0; i < 50; i++) {
			Receipt receipt = new Receipt();
			receipt.setNum(i+"");
			receipt.setAccidentType("箱损");
			receipt.setWarehouseCode("长沙");
			receipt.setOutboundDate("2020-08-04");
			receipt.setCarNo("赣 E27237");
			receipt.setDeliverCode("460041101");
			receipt.setMaterialCode("DYKTTG20230817_13");
			receipt.setMaterialName("新能效26云佳一级+新能效26云佳+新能效35云佳X+京东云逸-ⅡX三级72机");
			list.add(receipt);
		}
		dataMap2.put("receiptList", list);
		return dataMap2;
	}
}

